//
// Created on 2024/9/5.
//
// Node APIs are not fully supported. To solve the compilation error of the
// interface cannot be found, please include "napi/native_api.h".

#pragma once

#include "media/base/media_channel.h"
#include "modules/video_capture/video_capture.h"
#include "modules/video_capture/video_capture_defines.h"
#include "rtc_client/render/njs_video_render.h"
#include <js_native_api_types.h>

namespace ohosrtc {

class NJSCameraCapture : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
  public:
    static std::string GetCameraDeviceId(bool is_front);
    NJSCameraCapture(int width, int height, int targetFps, std::string deviceUniqueIdUTF8);
    virtual ~NJSCameraCapture() = default;

    bool StartCapture();
    void StopCapture();
    void SetWindowOrientation(int orientation);
    void SetSensorOrientation(int orientation);

    void OnFrame(const webrtc::VideoFrame &frame);

    void BindPreviewRender(std::string renderId);
     
    void BindSink(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
      
    void ClearSinks();
  
  private:
    std::uint32_t width_, height_, targetFps_;
    rtc::scoped_refptr<webrtc::VideoCaptureModule> cppImpl_;
    webrtc::VideoCaptureCapability capability_;
    std::list<std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>>> sinks_;
};
} // namespace ohosrtc